package com.yuanheng100.ems4j.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by jlqian on 2017/1/12.
 */
public class Ems4jEmployeeSQLProvider
{
    public String selectEmployeeListByDepIdRoleIdStatus(@Param("depId") final int depId, @Param("roleId") final int roleId, @Param("status") final short status)
    {
        return new SQL()
        {{
            SELECT("e.*");
            FROM("ems4j_employee e");
            if (roleId != 0)
            {
                LEFT_OUTER_JOIN("ems4j_emp_role er ON e.userid = er.userid");
            }
            WHERE("e.department = #{depId,jdbcType=INTEGER}");
            if (roleId != 0)
            {
                WHERE("er.roleId = #{roleId,jdbcType=INTEGER}");
            }
            if (status != 0)
            {
                WHERE("e.empStatus = #{status,jdbcType=SMALLINT}");
            }
        }}.toString();
    }
}
